$(function () {
    $(window).on("load", () => {
        class Index {
            constructor() {
                this.init();
            }
            init() {
                this.user_dropdown = $("#userDropdown")
                this.login_btn = $("#loginBtn")
                this.nickname = $("#nickname")

                this.ID = cookie("ID");
                this.TOKEN = cookie("TOKEN");

                if (this.ID.length > 0 && this.TOKEN.length > 0) {
                    this.user_dropdown.css("display", "inline-block");
                    //存在免登录信息;
                    this.getUserInfo();
                } else {
                    //没有登录信息，展示登录按钮
                    this.login_btn.css("display", "inline-block")
                }
            }

            getUserInfo() {
                var _this = this;
                $.ajax({
                    url: "http://localhost:8888/users/info/" + this.ID,
                    headers: {
                        "authorization": this.TOKEN
                    },
                    dataType: "json",
                    
                }).then(function(res){
                    _this.nickname.html(res.info.nickname);
                })
                
            }
        }
        new Index
    })
})